package com.yyge;

import com.yyge.dao.BookDao;
import com.yyge.service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * ioc控制反转
 */

public class App {
    public static void main(String[] args) {
      String configPath="classpath:applictionContext.xml";

        // 基于XML配置IOC容器,由spring负责实现
        ApplicationContext context=new ClassPathXmlApplicationContext(configPath);

        // 从IOC容器中获取bean  BookDao.class-->对应配置文件中实现了BookDao接口的对象-是唯一的
        BookDao bookDao=context.getBean(BookDao.class);
        bookDao.function();
        //--->这是BookDaoImpl的Function...


        BookService service = context.getBean(BookService.class);
        service.function();
        //--->这是实现Bookservice接口的Function...
    }
}
